package com.woniuxy.controller;

import com.woniuxy.entity.ClassName;
import com.woniuxy.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * @Author: ideaAdmin
 * TODO:接受form 标记提交的数据
 * Date: 2022/1/24:16:28
 * Description:
 */
@Controller
@RequestMapping("/form")
public class ParamsSendAndAccept {
    /**
     * @Author ideaAdmin
     * TODO:接受单个字符串
     * @Date 17:30 2022/1/24
     * * @param name
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/StringValue")
    public ModelAndView acceptParams(@RequestParam("name")  String... name){
        ModelAndView modelAndView = new ModelAndView();
        String a = "";
        for (int i = 0; i <name.length; i++) {
            a += name[i];
        }
        modelAndView.addObject("msg","接受的参数" + a);
        modelAndView.setViewName("test");
        return modelAndView;
    }



    /**
     * @Author ideaAdmin
     * TODO:接收数组
     * @Date 17:30 2022/1/24
     * * @param ids
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @ResponseBody
    @RequestMapping("/Arrays")
    public ModelAndView acceptParams(int[] ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接受的参数" + new ArrayList<>(Arrays.asList(ids)));
        modelAndView.setViewName("test");
        return modelAndView;
    }

    /**
     * @Author ideaAdmin
     * TODO: 把数据封装成list
     * @Date 17:31 2022/1/24
     * * @param ids
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/list")
    public ModelAndView acceptParams(@RequestParam List ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接受的参数" + ids.toString());
        modelAndView.setViewName("/index.jsp");
        return modelAndView;
    }


    /**
     * @Author ideaAdmin
     * TODO:把数据封装成map
     * @Date 17:33 2022/1/24
     * * @param ids
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/map")
    public ModelAndView acceptParams(@RequestParam Map<String,Object> ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接受的参数" + ids.toString());
        modelAndView.setViewName("test");
        return modelAndView;
    }

    /**
     * @Author ideaAdmin
     * TODO:把数据封装成对象 一对一
     * @Date 17:36 2022/1/24
     * * @param ids
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/student")
    public ModelAndView acceptParams(Student student){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接受的参数" + student.toString());
        modelAndView.setViewName("test");
        return modelAndView;
    }

    /**
     * @Author ideaAdmin
     * TODO:封装对象 一对多
     * @Date 17:57 2022/1/24
     * * @param className
     * * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/className")
    public ModelAndView acceptParams(ClassName className){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接受的参数" + className.toString());
        modelAndView.setViewName("test");
        return modelAndView;
    }




}
